<template>
	<view>
		<!-- 橙色部分 -->
		<view class="situation"></view>
		<!-- 信息卡片 -->
		<view class="contain">
			<view class="info_img">
				<image :src="avatar"></image>
			</view>
			<view class="info_content">请求加入{{institution}}</view>
			<view class="info_detail">
				<view class="info_name">{{name}}</view>
				<!-- 	<image src="https://img-blog.csdnimg.cn/20210328175130124.png"></image>
				<view style="color: #666;">女</view> -->
			</view>
			<view class="info_identity" v-for="(item, index) in studenInfo" :key="index">
				<view class="info_item">{{item.title}}</view>
				<view class="info_text">{{item.value}}</view>
			</view>
			<view class="info_identity">
				<view class="info_item">个人简历</view>
				<textarea :value="introduction" disabled></textarea>
			</view>
			<view class="info_btn">
				<button @click="judging_false">不通过</button>
				<button @click="judging_true">通过</button>
			</view>
		</view>
	</view>
</template>

<script>
	import cloudbase from '@cloudbase/js-sdk';

	const db = cloudbase.database();
	const dbCmd = db.command;
	let audit;
	export default {
		data() {
			return {
				name: '',
				avatar: '',
				studenInfo: [{
					title: '身份',
					value: '学生'
				}, {
					title: '出生年月',
					value: '2020年1月1日'
				}, {
					title: '手机号',
					value: '19999999999'
				}],
				introduction: '热爱生活, 热爱音乐, 希望世界和平',
				institution: '麻涌地区快学机构'
			}
		},
		onLoad(item) {
			this.institution = getApp().globalData.userInfo.institution;
			if (item.info) {
				let info = JSON.parse(item.info);
				console.log(info);
				audit = info;
				this.name = info.name;
				// 获取学生信息
				this.getStudentInfo(info);
			}

		},
		methods: {
			getStudentInfo: function(info) {
				let that = this;
				db.collection('user').where({
					openId: info.openId
				}).get().then(res => {
					console.log(res.data[0]);
					let student = res.data[0];
					that.avatar = student.avatarUrl;
					that.introduction = student.introduction;
					that.studenInfo[0].value = student.type;
					that.studenInfo[1].value = student.birthday;
					that.studenInfo[2].value = student.phone;
				})
			},
			judging_true: function() {
				// 审核通过，修改用户所在机构
				db.collection('user').where({
					openId: audit.openId
				}).update({
					institutionId: getApp().globalData.userInfo.institutionId,
					institution: getApp().globalData.userInfo.institution
				}).then(res => {
					console.log(res);
					if (res.updated == 1) {
						// 将审核信息修改为完成
						db.collection('audit').where({
							_id: audit._id
						}).update({
							finish: true
						}).then(res => {
							if(res.updated == 1) {
								uni.navigateTo({
									url: '../commitSuccess/commitSuccess?content=审核通过'
								})
							}
						})
					}
				})

			},
			judging_false: function() {
				uni.navigateTo({
					url: '../commitSuccess/commitSuccess?content=审核不通过'
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #F3F5F7;
	}

	.situation {
		background-color: #FD973F;
		width: 100%;
		height: 300rpx;
		border-radius: 0 0 30% 30%;
		display: flex;
		flex-direction: column;
		text-align: center;
	}

	.contain {
		margin: -110rpx 30rpx;
		/* height: 300rpx; */
		background-color: #fff;
		border-radius: 24rpx;
		padding: 20rpx 30rpx;
	}

	.info_img {
		width: 100%;
		text-align: center;
	}

	.info_img image {
		width: 200rpx;
		height: 200rpx;
		border-radius: 50%;
		margin-top: -120rpx;
	}

	.info_content {
		width: 100%;
		text-align: center;
		font-size: 36rpx;
		font-weight: bold;
		margin: 20rpx 0;
	}

	.info_detail {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 50rpx;
	}

	.info_name {
		/* margin-right: 60rpx; */
		/* font-size: 33rpx; */
	}

	.info_detail image {
		width: 40rpx;
		height: 40rpx;
		margin-right: 10rpx;
	}

	.info_identity {
		display: flex;
		margin-bottom: 60rpx;
	}

	.info_item {
		font-weight: bold;
		width: 200rpx;
		margin-left: 50rpx;
	}

	.info_text {
		color: #666;
		width: calc(100% - 200rpx);
	}

	.info_identity textarea {
		background-color: #FFECDA;
		width: calc(100% - 200rpx);
		border-radius: 24rpx;
		padding: 30rpx 30rpx 0rpx 30rpx;
		color: #666;
		height: 250rpx;
	}

	.info_btn {
		width: 100%;
		display: flex;
		justify-content: center;
	}

	.info_btn button {
		background-color: #FD973F;
		color: #fff;
		border-radius: 34rpx;
		width: 200rpx;
	}
</style>
